package com.hey.baseapplication.api;

import android.util.Log;

import com.hey.baseapplication.BuildConfig;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Hey on 16/12/15.
 */

public class RetrofitClient {
    public static  final  boolean DEBUG= BuildConfig.DEBUG;
    private  static Retrofit instance;

    public static ApiService getInstance(){
        if (instance==null){
            synchronized (RetrofitClient.class){
                if (instance==null){
                    HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor();
                    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                    OkHttpClient client=new OkHttpClient.Builder().addInterceptor(loggingInterceptor).build();
                    instance=new Retrofit.Builder()
                            .client(client)
                            .addConverterFactory(GsonConverterFactory.create())
                            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                            .baseUrl(getBaseUrl())
                            .build();
                }
            }
        }
        return  instance.create(ApiService.class);
    }

    public  static String getBaseUrl(){
        Log.e("debug",DEBUG?"http://139.196.32.98/api1_3_8/":"haha");
        return DEBUG?"http://139.196.32.98/api1_3_8/":"http://139.196.32.98/api1_3_8/";
    }

}
